<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.servicemanagement.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesAdd.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicenum") %></label>
						<span><input type="text" id="servicenum" name="servicenum" class="validate[required,maxSize[10]]" /></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicename") %></label>
						<span><input type="text" id="servicename" name="servicename" class="validate[required,maxSize[50]]" /></span>
					</li>
				</ul>
				<ul>
					<li>
						<i>&nbsp;</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.remark") %></label>
						<span><textarea id="remark" name="remark" rows="2" cols="45" class="validate[maxSize[1000]]"></textarea></span>
					</li>
				</ul>
			</div>			
			<!-- 分配服务菜单权限 start -->
			<div  style="border: 1px solid #e0e0e0;background:#fff;padding-top: 9px;height:350px;width: 99%;">
				<span style="color: red;padding-left: 5px;padding-right: 6px">*</span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesAdd.fenpeimenu") %>
	       		<div  style="margin-top: 9px;height:300px;overflow-y:auto;">
	       			<ul id="menuTree" class="ztree" style="padding-left: 13px;"></ul>
	       		</div>
       		</div>
			<!-- 分配服务菜单权限end -->
        	
		</div>
		<div class="button-group" style="padding-top: 10px">
       			<input type="hidden"  name="menuids" id="menuids" value=""/>
       			<input type="button" class="btn btn-default"  id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
       			<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
	</div>
</form>

<script type="text/javascript">	
$(document).ready(function() {
	
	function asyncMenu(){
		var zTree = $.fn.zTree.getZTreeObj("menuTree");
		asyncMenuNodes(zTree.getNodes());
		//zTree.expandAll(true);//true表示所有父节点全部展开
	}
	
	function asyncMenuNodes(nodes){
		if(!nodes) return;
		var zTree = $.fn.zTree.getZTreeObj("menuTree");
		for (var i=0, l=nodes.length; i<l; i++) {//遍历外层节点
			if (nodes[i].isParent && nodes[i].zAsync) {//如果是父节点并且父节点没有加载过
				asyncMenuNodes(nodes[i].children);//在这种条件下继续递归遍历该父节点的所有子节点
			} else {//如果不是父节点或者父节点已经加载过
				zTree.reAsyncChildNodes(nodes[i], "refresh", true);//清空后不展开父节点，其他值或缺省状态都自己展开
			}
		}
	}

	function onCheck(event, treeId, treeNode){
        var treeObj=$.fn.zTree.getZTreeObj("menuTree"),
        nodes=treeObj.getCheckedNodes(true),
        menuids="";
        for(var i=0;i<nodes.length;i++){
            /* if(nodes[i].isParent){
            	menuids+=nodes[i].menuid + ",";
            }else{ */
            	menuids+=nodes[i].menuid + ",";
            /* } */
        }
       	$('#menuids').val(menuids);
    }
	
	var menusetting = {
			async: {
				enable:true,
				url:"${systemctx}/dailyoperation/services/queryMenuDirectoryTree.json",
				autoParam: ["menucode","menuid","menulevel"]
			},check:{
				enable:true
			},data:{
				simpleData:{
					enable:true,
					idKey:"menucode",
					rootPid:0
				}
			},callback:{
				onAsyncSuccess:asyncMenu,
				onCheck:onCheck
			}
	};
	
	$.fn.zTree.init($("#menuTree"), menusetting);//初始化zTree，第三个参数没有则表明用异步加载
	var zTree2 = $.fn.zTree.getZTreeObj("menuTree");
	zTree2.setting.check.chkboxType = { "Y" : "ps", "N" : "ps" };//checkbox（Y）勾选后和取消（N）都对父节点（p）和对子节点（s）有影响

	$('#butSave').click(function() {
		var exp = $('#form1').validationEngine('validate');
		var menuids = $('#menuids').val();
			
		if(exp==true)
		{
			if(menuids == ""){
				alert('<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.storeservicesguajieAdd.alert3")%>');
			}else{
				// 显示进度条
				showSending();
				$.ajax({
					type: 'POST',
				    url: '${systemctx}/dailyoperation/services/validattionServices.json',
				    data: $("#form1").serialize(),
				    dataType: 'json',
				    success: function(data)
				    {
				    	//关闭执行...
						closeSending();
				    	if (data.messagetype == '2')
				    	{
				    		//显示AJAX请求后的提示信息
							$.fn.ajaxmessage(data);
					   	}
					   	else
				    	{
				    		showSending();
				    		form1.action="${systemctx}/dailyoperation/services/addServices.web";
							form1.submit();
				    	}
				    }
				});
			}
		}  
	});

	$('#butReturn').click(function(){
		parent.document.location.reload();
	    $.fn.closeIssWindow();
	});
});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>